package com.vnaloha.common.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vnaloha.common.dao.DocumentDAO;
import com.vnaloha.common.model.Document;

@Service
public class DocumentServiceImpl implements DocumentService{

	private Logger logger = LoggerFactory.getLogger(DocumentServiceImpl.class);
	
	@Autowired
	private DocumentDAO documentDAO;
	
	/*
	 * (non-Javadoc)
	 * @see com.vnaloha.common.service.DocumentService#save(com.vnaloha.common.model.Document)
	 */
	@Override
	@Transactional
	public void save(Document document) {
		
		logger.info("Save document to database: " + document);
		documentDAO.save(document);
		
	}

	/*
	 * (non-Javadoc)
	 * @see com.vnaloha.common.service.DocumentService#list()
	 */
	@Override
	@Transactional
	public List<Document> list() {
		
		logger.info("Get list document");
		return documentDAO.list();
	}

	/*
	 * (non-Javadoc)
	 * @see com.vnaloha.common.service.DocumentService#get(java.lang.Integer)
	 */
	@Override
	@Transactional
	public Document get(Integer id) {
		
		logger.info("Find document by id: " + id);
		return documentDAO.get(id);
	}

	/*
	 * (non-Javadoc)
	 * @see com.vnaloha.common.service.DocumentService#delete(java.lang.Integer)
	 */
	@Override
	@Transactional
	public void delete(Integer id) {
		
		logger.info("Delete document by id: " + id);
		documentDAO.delete(id);
	}

}
